package com.atgion.service.controller;

import com.atgion.service.CsFeignClient;
import com.atgion.service.ManagerFeignClient;
import com.atgion.service.service.UserInfoService;
import com.atgion.spzx.model.dto.h5.UserRegisterDto;
import com.atgion.spzx.model.dto.system.SysUserLoginParam;
import com.atgion.spzx.model.entity.system.SysUser;
import com.atgion.spzx.model.vo.base.Result;
import io.seata.spring.annotation.GlobalTransactional;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "会员用户接口")
@Slf4j
@RestController
@RequestMapping("/api/user/userInfo")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private ManagerFeignClient managerFeignClient;

    @Autowired
    private CsFeignClient client;

    @Operation(summary = "会员注册")
    @PostMapping("/register")
    public Result register(@RequestBody UserRegisterDto userRegisterDto) {
        userInfoService.register(userRegisterDto);
        return Result.success();
    }

    @Operation(summary = "会员登录")
    @PostMapping("/api/user/userInfo/login")
    public Result login(@RequestBody SysUserLoginParam sysUserLoginParam) {
        return   managerFeignClient.login(sysUserLoginParam);
    }

    @Operation(summary = "获取用户信息")
    @GetMapping("/auth/getCurrentUserInfo")
    public Result getCurrentUserInfo() {
        SysUser userInfoVo = userInfoService.getCurrentUserInfo();
        return Result.success(userInfoVo) ;
    }
    @GetMapping("/aa")
    @GlobalTransactional  //事务
    public Result aa(@RequestHeader("Authorization") String authorizationHeader) {
//        SysUser sysUser = userInfoService.getById(2);
        client.aa();
//        sysUser.setNickName("Syuaccc");
//        userInfoService.updateById(sysUser);
        return Result.success("aa");
    }

    //    用户退出
    @GetMapping("/logout")
    public Result logout(@RequestHeader("Authorization") String authorizationHeader){
        return managerFeignClient.logout(authorizationHeader);
    }

}
